using System;

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

using System.Security;
using System.Security.Permissions;

using System.Runtime.Serialization;

namespace CodePlex.Diagnostics
{
    /// <summary>
    /// Indicates that the <see cref="M:System.ThreadException.InnerException"/> was caught within an event handler for the <see cref="E:System.Windows.Forms.Application.ThreadException"/> event.
    /// </summary>
    /// <remarks>
    /// The <see cref="T:CodePlex.Diagnostics.ThreadException"/> class does not contain the standard exception constructors because instances of this type would be invalid without 
    /// the <see cref="M:CodePlex.Diagnostics.ThreadException.InnerException"/>.
    /// </remarks>
    [SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors"), Serializable]
    public sealed class ThreadException : Exception
    {
        #region public ThreadException(Exception inner) : base(SR.GetString(SR.ThreadException), inner)

        /// <summary>
        /// Initializes a new instance of the <see cref="T:ThreadException"/> class with the specified detailed description and the specified exception. 
        /// </summary>
        /// <param name="inner">A reference to the inner exception that is the cause of this exception.</param>
        [SecurityPermission(SecurityAction.LinkDemand)]
        public ThreadException(Exception inner) : base(SR.GetString(SR.ThreadException), inner)
        {
        }

        #endregion

        #region private ThreadException(SerializationInfo info, StreamingContext context) : base(info, context)

        /// <summary>
        /// Initializes a new instance of the <see cref="T:ThreadException"/> class.
        /// </summary>
        /// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
        /// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination.</param>
        /// <exception cref="T:System.Runtime.Serialization.SerializationException">The class name is <c>null</c> or <see cref="P:System.Exception.HResult"/> is zero (0).</exception>
        /// <exception cref="T:System.ArgumentNullException">The info parameter is <c>null</c>.</exception>
        [SecurityPermission(SecurityAction.LinkDemand, SerializationFormatter = true)]
        private ThreadException(SerializationInfo info, StreamingContext context) : base(info, context)
        {

        }

        #endregion

        #region public override void GetObjectData(SerializationInfo info, StreamingContext context)

        /// <summary>
        /// Sets the <see cref="T:System.Runtime.Serialization.SerializationInfo"/> with information about the exception.
        /// </summary>
        /// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
        /// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination.</param>
        /// <exception cref="T:System.ArgumentNullException">The info parameter is a <c>null</c> reference (Nothing in Visual Basic). </exception>
        /// <PermissionSet>
        /// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Read="*AllFiles*" PathDiscovery="*AllFiles*"/>
        /// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="SerializationFormatter"/>
        /// </PermissionSet>
        [SecurityPermission(SecurityAction.LinkDemand, SerializationFormatter = true)]
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            base.GetObjectData(info, context);
        }

        #endregion
    }
}
